home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / Examples / Text / Textension / Include / StyledText.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-21  |  2.8 KB  |  116 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        StyledText.h
  3.  
  4.     Contains:    xxx put contents here xxx
  5.  
  6.     Written by:    Essam Zaky
  7.  
  8.     Copyright:    © 1994 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <2>      1/4/94    EZ        clean up
  13.          <1>      1/4/94    EZ        first checked in
  14.  
  15. */
  16.  
  17. #ifndef _StyledText_
  18. #define _StyledText_
  19.  
  20. #ifndef _ToolBoxDump_
  21. #include "ToolBoxDump.h"
  22. #endif
  23.  
  24. #ifndef _AttrObject_
  25. #include "AttrObject.h"
  26. #endif
  27.  
  28. #ifndef _RunObject_
  29. #include "RunObject.h"
  30. #endif
  31.  
  32. #ifndef _RunsRanges_
  33. #include "RunsRanges.h"
  34. #endif
  35.  
  36. //***************************************************************************************************
  37.  
  38. struct TTextEnv {
  39.     TTextEnv(char nesting = 0) {allowNesting = nesting;}
  40.     
  41.     char allowNesting;
  42.     GrafPtr savedPort;
  43.     short savedSysJust;
  44.     long    savedFontForce;
  45. };
  46.  
  47. class    CStyledText    : public HandleObject {
  48.     public:
  49. //-------
  50.     CStyledText();
  51.     
  52.     void IStyledText(GrafPtr textPort, CRunObject* protoObj, TSize sizeInfo = kLargeSize);
  53.     virtual void Free();
  54.  
  55.     inline CRunsRanges* GetRunsRanges() {return fRunsRanges;}
  56.     
  57.     virtual void SetTextPort(GrafPtr newPort);
  58.     GrafPtr GetTextPort() const;
  59.     
  60.     virtual void SetTextEnv(TTextEnv* savedTextEnv);
  61.     virtual void RestoreTextEnv(const TTextEnv& savedTextEnv);
  62.     
  63.     inline void* LockChars(Boolean moveHi = false) {return fTextChars->LockArray(moveHi);}
  64.     inline void UnlockChars() {fTextChars->UnlockArray();}
  65.     
  66.     #ifdef txtnNever
  67.     inline OSErr SetCharsSize(long newCharsCount, Boolean compact =false)
  68.         {return fTextChars->SetElementsCount(newCharsCount, compact);}
  69.     #endif
  70.     
  71.     inline uPtr GetCharPtr(long charOffset) const
  72.         {return (uPtr(fTextChars->GetElementPtr(charOffset)));}
  73.         
  74.     inline long    CountChars() const {return (fTextChars->CountElements());}
  75.     
  76.     virtual void WordBoundaries(TOffsetRange* wordRange);
  77.     
  78.     short AdvanceOffset(long charOffset, Boolean forward);
  79.     
  80.     inline CRunObject* Char2Run(TOffset charOffset) //returns nil if text is empty
  81.         {return (CRunObject*)(fRunsRanges->Offset2Object(charOffset));}
  82.     
  83.     inline CRunObject* Char2TextRun(TOffset charOffset) const
  84.         {return fRunsRanges->Char2TextRun(charOffset);}
  85.     
  86.     #ifdef txtnDebug
  87.     inline char TextEnvLevel() {return fTextEnvLevel;}
  88.     #endif
  89.  
  90.     protected:
  91. //----------
  92.     GrafPtr    fTextPort;
  93.     
  94.     CArray*    fTextChars;
  95.     CRunsRanges*    fRunsRanges;
  96.  
  97.     
  98.     char CalcNextScriptRun(long offset, long len, long* scriptRunLen); //call FindScriptRun
  99.     OSErr Run2ScriptRuns(long runOffset, long runLen, const CRunObject* defaultRun);
  100.     
  101.     OSErr    CalcScriptRuns(const CRunObject* defaultRun, char* majorDirection);
  102.     //defaultRun may be nil
  103.     
  104.     short GetByteOrder(uPtr chars, short offset, short charScript);
  105.     //returns the same result as CharByte
  106.         
  107.     private:
  108. //--------
  109.     CRunObject*    fSavedObj;
  110.     
  111.     char        fTextEnvLevel; //allow nested calls to SaveTextEnv and RestoreTextEnv
  112. };
  113. //***************************************************************************************************
  114.  
  115. #endif
  116.